//
//  HtmlTextView.swift
//  maozzi-rss
//
//  Created by 帽子 on 2020/5/31.
//  Copyright © 2020 帽子. All rights reserved.
//	WKWebView html 文本显示

import SafariServices
import SwiftUI
import WebKit

struct HtmlWebView: UIViewRepresentable {
    let htmlContent: String

    func makeUIView(context: Context) -> WKWebView {
        return WKWebView()
    }

    func updateUIView(_ uiView: WKWebView, context: Context) {
        uiView.loadHTMLString(htmlContent, baseURL: nil)
    }
}

struct HtmlSafariView: UIViewControllerRepresentable {
    var url: URL

    func makeUIViewController(context: Context) -> SFSafariViewController {
        let conf = SFSafariViewController.Configuration()
        conf.entersReaderIfAvailable = true
        conf.barCollapsingEnabled = false
        return SFSafariViewController(url: url, configuration: conf)
    }

    func updateUIViewController(_ uiViewController: SFSafariViewController, context: Context) {
    }
}

struct HtmlView_Previews: PreviewProvider {
    static var previews: some View {
        HtmlSafariView(url: URL(string: "https://www.baidu.com")!)
    }
}
